/**
 * 
 */
package org.trajectory.web.rest.resources;

import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException;
import org.pentaho.platform.api.repository.datasource.IDatasource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.trajectory.dao.ConnectionService;

/**
 * @author Administrator
 *
 */
@Component
@Path("/trajectory/resource/query")
public class QueryResource {
	private ConnectionService connectionService;
	
	
	@Autowired
	public void setConnectionService(ConnectionService connectionService) {
		this.connectionService = connectionService;
	}



	@GET
	@Produces({"application/json"})
	public List<String> getResources() throws DatasourceMgmtServiceException{
		List<IDatasource> result = connectionService.getConnections();
		List<String> names = new ArrayList<String>(result.size());
		for(IDatasource d : result){
			names.add(d.getName());
		}
		return names;
	}
}
